package com.lecture.springlecture;

import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@Slf4j
@MapperScan("com.lecture.springlecture.dao")
@EnableAsync
@EnableCaching
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "3m")
public class SpringLectureApplication {
	public static void main(String[] args) {
		ConfigurableApplicationContext run = SpringApplication.run(SpringLectureApplication.class, args);
		for (String beanDefinitionName : run.getBeanDefinitionNames()) {
			System.out.println(beanDefinitionName);
		}
		Environment env = run.getEnvironment();

		// 打印 Redis 配置
		System.out.println("Redis Host: " + env.getProperty("spring.redis.host"));
		System.out.println("Redis Port: " + env.getProperty("spring.redis.port"));

		// 打印所有配置（调试用）
		System.out.println("===== All Properties =====");
		((AbstractEnvironment) env).getPropertySources().forEach(ps -> {
			if (ps instanceof MapPropertySource) {
				System.out.println("PropertySource: " + ps.getName());
				((MapPropertySource) ps).getSource().forEach((key, value) -> {
					System.out.println(key + " = " + value);
				});
			}
		});
		//KieSessionFactory.getKieSession();
		/*SpringApplication springApplication = new SpringApplication(SpringLectureApplication.class);
		springApplication.setBannerMode(Banner.Mode.OFF);
		springApplication.run(args);*/
	}
}
